package cn.maxwell.basic.config.interceptor;

import cn.maxwell.basic.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//表示该类是配置类
public class MyWebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 添加拦截器，可以添加多个
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器：要添加那个拦截器，就注入哪个拦截器
        registry.addInterceptor(loginInterceptor)
            //拦截所有请求
            .addPathPatterns("/**")
            //放行登录的请求
            .excludePathPatterns("/login/**")
            //放行跟注册有关的:用户注册，图片验证码+短信验证码
            .excludePathPatterns("/user/*/register","/verifyCode/**","/user/register/phone")
            //放行店铺入驻，logo上传请求（文件上传接口）
            .excludePathPatterns("/shop/settlement","/fastDfs/**")
			//放行swagger
            .excludePathPatterns("/swagger-resources/**", "/webjars/**", 
                                 "/v2/**", "/swagger-ui.html/**");
            //如果写了邮箱激活还要放行邮箱
    }
}